package com.neuedu.controller;

import java.io.IOException;
import java.sql.Timestamp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neuedu.projos.Cate;
import com.neuedu.service.CateServ;
import com.neuedu.service.CateServImpl;

/**
 * Servlet implementation class addToCate
 */
@WebServlet("/addToCate")
public class addToCate extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public addToCate() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String pid =request.getParameter("cate");
		String cName =request.getParameter("cate2");
		int cpid=Integer.parseInt(pid);
		CateServ cate = new CateServImpl();
		Cate ct = new Cate(null, cName, cpid, new Timestamp(System.currentTimeMillis()));
		cate.addCate(ct);
		response.sendRedirect("CateController?pageNum=1");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
